<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>axios_basic</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
</head>
<body>
  <div>
    <title>基本使用</title>
    <button id="btn_get">GET请求</button>
    <button id="btn_post_add">POST请求_ADD</button>
    <button id="btn_post_del">POST请求_DEL</button>
  </div>
<script type="text/javascript">
  const btnGet = document.getElementById('btn_get')
  const btnPostAdd = document.getElementById('btn_post_add')
  const btnPostDel = document.getElementById('btn_post_del')

  btnGet.addEventListener('click', function(){
    axios({
      headers: {
        'Content-Type': 'application/json',
      },
      method: 'GET',
      url: 'http://localhost:3100/icloud/mock/user/list'
    }).then(response=>{
      console.log("data:", response)
    }, error=>{
      console.log(error);
    })
  })

  btnPostAdd.addEventListener('click', function(){
    axios({
      headers: {
        'Content-Type': 'application/json',
      },
      method: 'POST',
      url: 'http://localhost:3100/icloud/mock/user/add',
      data: {
        username:"老王",
        password:"123",
        birthday:"1992-03-21 02:12:32"
      }
    }).then(response=>{
      console.log("data:", response)
    }, error=>{
      console.log(error);
    })
  })

  btnPostDel.addEventListener('click', function(){
    axios({
      headers: {
        'Content-Type': 'application/json',
      },
      method: 'POST',
      url: 'http://localhost:3100/icloud/mock/user/del',
      data: {
        id: 1
      }
    }).then(response=>{
      console.log("data:", response)
    }, error=>{
      console.log(error);
    })
  })

</script>
</body>
</html>